package com.example.demo.controller;

import com.example.demo.model.Problem;
import com.example.demo.model.Question;
import com.example.demo.service.ProblemService;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created by xiebang
 * Description
 * User:小谢
 * Date:2022-09-19
 * Time:23:32
 */
@Controller

public class ProblemController {
    @Autowired
    private ProblemService problemService;

//    展示题目列表
    @RequestMapping("/problems")
    @ResponseBody
    public List<Problem> selectAll(){
        return problemService.selectAll();
    }

//    获取题目详情
    @RequestMapping("/problemdetail")
    @ResponseBody
    public Problem selectOne(Integer id){
        return problemService.selectOne(id);
    }

//    新增题目
    @RequestMapping("/addproblem")
    public String insert(@RequestBody Problem problem, HttpServletResponse resp) {
       int result =  problemService.insert(problem);
      return "redirect:/adminList.html";
}

//删除题目
    @RequestMapping("/deleteproblem")

    public String deleteProblem(Integer id){
        int result = problemService.deleteProblem(id);
        return "redirect:/adminList.html";
    }
}
